package design.proxy;

import java.lang.reflect.Proxy;

public class Test {
    public static void main(String[] args) {
        // 静态代理
        IStarEvent star = new RealStar();
        StaticProxy proxy = new StaticProxy(star);
        proxy.saleTicket();
        proxy.sing();
        proxy.receiveMoney();

        // 动态代理
        IStarEvent star1 = new RealStar();
        StarHandler handler = new StarHandler(star1);
        IStarEvent dynamicProxy = (IStarEvent) Proxy.newProxyInstance(
                ClassLoader.getSystemClassLoader(), new Class[]{IStarEvent.class}, handler);
        dynamicProxy.saleTicket();
        dynamicProxy.sing();
        dynamicProxy.receiveMoney();
    }
}




